package com.yuanxin.chooseimage.customutil;

import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;

import java.io.IOException;

/**
 * Created by lz on 2017/11/21.
 */

public class VideoUtil {
    public static Bitmap getVideoThumbnail(String videoPath) {
        MediaMetadataRetriever media = new MediaMetadataRetriever();
        media.setDataSource(videoPath);
        Bitmap bitmap = media.getFrameAtTime();
        return bitmap;
    }

    public static int getVideoDuration(String videoPath) {
        try {
            MediaPlayer mediaPlayer = new MediaPlayer();
            mediaPlayer.setDataSource(videoPath);
            mediaPlayer.prepare();
            return mediaPlayer.getDuration();
        } catch (Exception ex) {
            return 0;
        }
    }
}
